// var i;
// var $uI_MosterLogic_UIBindings = require("./UI_MosterLogic_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $eventManager = require("./EventManager");
// var $evenType = require("./EvenType");
// var $nodePoolMag = require("./NodePoolMag");
// var $excel = require("./Excel");
// var $buffMag = require("./BuffMag");
// var $bundleConfig = require("./BundleConfig");
// var $uI_HuDun = require("./UI_HuDun");
// var $uI_MosterXueTiao = require("./UI_MosterXueTiao");
// var $logManager = require("./LogManager");
// var $gameDataManager = require("./GameDataManager");
// var $gameGlobalVariable = require("./GameGlobalVariable");
// var $audioManager = require("./AudioManager");
// var M = cc._decorator;
// var E = M.ccclass;
// var x = M.property;
// var C = M.inspector;
// var B = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.mosterId = 1;
//         t.hunmoNode = null;
//         t.mosterXueTiao = null;
//         t.xueliang = 0;
//         t.maxxueliang = 0;
//         t.mosterspeed = 0;
//         t.defy = 999999;
//         t.liuxueContentNode = null;
//         t.zhengshangNode = null;
//         t.nowmosterdata = null;
//         t.paths = null;
//         t.nowtexindex = 0;
//         t.twmove = null;
//         t.nowHuDunNode = null;
//         t.iszhaohuan = !1;
//         t.zhaohuantime = 100;
//         t.isXiGuaBomb = !1;
//         t.isDie = !1;
//         t.ohterbullet = null;
//         t.zhongduNode = null;
//         t.bingdongNode = null;
//         t.dongjieNode = null;
//         t.liuxueNode = null;
//         t.bingdongjianshu = 0;
//         t.isjianshu = !1;
//         t.jianshutime = 0;
//         t.isdongjie = !1;
//         t.dongjietime = 0;
//         t.iszhongdu = !1;
//         t.dushan = 0;
//         t.zhongdutime = 0;
//         t.isliuxue = !1;
//         t.liuxueshang = 0;
//         t.liuxuetime = 0;
//         t.isransao = !1;
//         t.ransaoshang = 0;
//         t.ransaotime = 0;
//         t.diejiacount = 0;
//         t.dushangplayer = null;
//         t.nowbuffatackplay = null;
//         t.ismove = !1;
//         t.moveindex = 0;
//         t.tesofftime = 0;
//         t.dutimeleiji = 0;
//         t.liutimeleiji = 0;
//         t.ransaotimeleiji = 0;
//         t.jiansuleiji = 0;
//         t.dongjieleiji = 0;
//         t.zhaohuantimeleiji = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {
//         this.node.children.forEach(function (e) {
//             e.active = !0;
//         });
//         if (999999 != this.defy) {
//             this.hunmoNode.y = this.defy;
//         } else {
//             this.defy = this.hunmoNode.y;
//         }
//         this.hunmoNode.active = !1;
//         this.node.getChildByName("dongImg").active = !1;
//         this.liuxueContentNode = this.node.getChildByName("liuxueNode");
//         this.zhengshangNode = this.node.getChildByName("zhengshang");
//         this.zhengshangNode.active = !1;
//     };
//     t.prototype.onDisable = function () {
//         if (this.nowHuDunNode) {
//             $nodePoolMag.NodePoolMag.instance.recycleNode("hudun", this.nowHuDunNode);
//             this.nowHuDunNode = null;
//         }
//         $buffMag.BuffMgr.cleanMosterBombCount(this);
//         this.cleanDuEff();
//         this.cleanBingEff();
//         this.cleanDongjieEff();
//         this.cleanLiuXueEff();
//         this.cleanXiGuaBomb();
//         this.unscheduleAllCallbacks();
//     };
//     t.prototype.setIsXiGuaBomb = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             return __generator(this, function () {
//                 if (!(this.isXiGuaBomb || this.isDie)) {
//                     this.isXiGuaBomb = !0;
//                     this.zhengshangNode.active = !0;
//                 }
//                 return [2];
//             });
//         });
//     };
//     t.prototype.cleanXiGuaBomb = function () {
//         this.zhengshangNode.active = !1;
//     };
//     t.prototype.setMosterInfo = function (e, t, o, n, i) {
//         if (void 0 === i) {
//             i = 1;
//         }
//         return __awaiter(this, void 0, void 0, function () {
//             var a;
//             var r;
//             var c;
//             var l;
//             var u;
//             var d;
//             var p;
//             var g;
//             var _;
//             var y;
//             return __generator(this, function () {
//                 this.isDie = !1;
//                 this.isXiGuaBomb = !1;
//                 this.nowtexindex = o;
//                 a = $excel.Excel.shuiguoguaiwu(e);
//                 this.nowmosterdata = a;
//                 this.mosterspeed = this.nowmosterdata.mosterspeed / 60;
//                 this.xueliang = this.nowmosterdata.mosterxue;
//                 r = 1;
//                 if (1 == $gameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
//                     c = $gameDataManager.GameDataMgr.getNowMaxLevel();
//                     l = $excel.Excel.shuiguoguanqia(c);
//                     u = l.levelboshuid[l.levelboshuid.length - 1];
//                     d = $excel.Excel.shuiguoboshu(u);
//                     r = d.mosterjiaxue;
//                 }
//                 if (n) {
//                     this.xueliang = this.nowmosterdata.mosterxue * n.mosterjiaxue * r;
//                 }
//                 this.maxxueliang = this.xueliang;
//                 this.mosterXueTiao.initXue(this.maxxueliang);
//                 this.moveindex = i;
//                 this.paths = t;
//                 this.updateXueTiao();
//                 this.ismove = !0;
//                 this.node.opacity = 0;
//                 cc.tween(this.node)
//                     .to(0.2, {
//                         opacity: 255
//                     })
//                     .start();
//                 p = this.auto_ui.node_piaozipos.children;
//                 g = p.length;
//                 for (_ = 0; _ < g; _++) {
//                     y = p[0];
//                     $nodePoolMag.NodePoolMag.instance.recycleNode("piaozi", y);
//                 }
//                 this.twmove = cc
//                     .tween(this.node.children[0])
//                     .to(0.25, {
//                         scaleY: 0.9
//                     })
//                     .to(0.25, {
//                         scaleY: 1
//                     });
//                 cc.tween(this.node.children[0]).repeatForever(this.twmove).start();
//                 return [2];
//             });
//         });
//     };
//     t.prototype.addHuDun = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             return __generator(this, function (t) {
//                 switch (t.label) {
//                     case 0:
//                         this.nowHuDunNode = $nodePoolMag.NodePoolMag.instance.getNode("hudun");
//                         return this.nowHuDunNode
//                             ? [3, 2]
//                             : [4, this._loadRes($bundleConfig.BundleNames.Game, "prefabs/effpre/UI_HuDun", cc.Prefab)];
//                     case 1:
//                         e = t.sent();
//                         $nodePoolMag.NodePoolMag.instance.createNodeCount("hudun", 1, e);
//                         this.nowHuDunNode = $nodePoolMag.NodePoolMag.instance.getNode("hudun");
//                         t.label = 2;
//                     case 2:
//                         this.auto_ui.node_hudunnode.addChild(this.nowHuDunNode);
//                         this.nowHuDunNode.getComponent($uI_HuDun.default).initHuDu(100);
//                         this.iszhaohuan = !1;
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.updateXueTiao = function () {
//         if (this.xueliang <= 0) {
//             this.isDieMoster();
//         }
//     };
//     t.prototype.isDieMoster = function (e) {
//         var t = this;
//         if (void 0 === e) {
//             e = 1;
//         }
//         if (!this.isDie) {
//             $buffMag.BuffMgr.cleanMosterDieJia(this);
//             $buffMag.BuffMgr.cleanMosterBomb(this.node.uuid);
//             var o = $buffMag.BuffMgr.getDuWu();
//             if (this.iszhongdu && o) {
//                 $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_CreateDuWu, this, o, this.dushangplayer);
//             }
//             if (this.ohterbullet && this.ohterbullet.attackfang) {
//                 $buffMag.BuffMgr.setBombShanHai(this.ohterbullet.attackfang, this);
//             }
//             this.node.children.forEach(function (e) {
//                 e.active = !1;
//             });
//             this.hunmoNode.active = !0;
//             this.hunmoNode.opacity = 255;
//             cc.tween(this.hunmoNode)
//                 .to(0.5, {
//                     y: this.hunmoNode.y + 100
//                 })
//                 .to(0.1, {
//                     opacity: 0
//                 })
//                 .call(function () {
//                     t.node.stopAllActions();
//                     t.unscheduleAllCallbacks();
//                     t.resetState();
//                     $nodePoolMag.NodePoolMag.instance.recycleNode("moster_" + t.mosterId, t.node);
//                 })
//                 .start();
//             this.isDie = !0;
//             this.ismove = !1;
//             if (1 == e) {
//                 $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_Moster_DIE, {
//                     moster: this.mosterId
//                 });
//             }
//         }
//     };
//     t.prototype.moveBu = function () {
//         if (this.ismove) {
//             var e = this.paths.children[this.moveindex];
//             if (!e) {
//                 this.isDieMoster(2);
//                 return void $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_Moster_Attack, {
//                     mosterId: this.mosterId
//                 });
//             }
//             var t = e.x;
//             var o = e.y;
//             if (0 == this.moveindex) {
//                 this.node.x = t;
//                 this.node.y = o;
//                 this.moveindex += 1;
//             } else {
//                 {
//                     var n = cc.Vec2.subtract(cc.v2(), cc.v2(t, o), this.node.getPosition());
//                     var i = Math.atan2(n.y, n.x);
//                     var a = cc.Vec2.distance(this.node.getPosition(), cc.v2(t, o));
//                     this.node.x += Math.cos(i) * this.nowspeed();
//                     this.node.y += Math.sin(i) * this.nowspeed();
//                     if (a < 5) {
//                         this.moveindex += 1;
//                     }
//                 }
//             }
//         }
//     };
//     t.prototype.getNowMosterNode = function (e) {
//         var t = this.node.parent.children;
//         var o = [];
//         for (var n = 0; n < t.length; n++) {
//             var i = t[n];
//             var a = cc.Vec2.distance(i.getPosition(), this.node.getPosition());
//             if ((a -= i.width / 2 + this.node.width / 2) <= e) {
//                 o.push(i);
//             }
//         }
//         return o;
//     };
//     t.prototype.backTui = function (e) {
//         var t = this;
//         if (this.moveindex >= 2) {
//             this.ismove = !1;
//             var o = this.moveindex - 1;
//             if (o < 0) {
//                 o = 0;
//             }
//             (function e(o, n) {
//                 var i = t.paths.children[n];
//                 if (i) {
//                     var a = i.x;
//                     var r = i.y;
//                     var c = cc.Vec2.distance(t.node.getPosition(), cc.v2(a, r));
//                     var s = 0;
//                     if (o > c) {
//                         s = o - c;
//                         o = c;
//                     }
//                     var l = cc.Vec2.subtract(cc.v2(), cc.v2(a, r), t.node.getPosition());
//                     var u = Math.atan2(l.y, l.x);
//                     var d = t.node.x + Math.cos(u) * o;
//                     var p = t.node.y + Math.sin(u) * o;
//                     cc.tween(t.node)
//                         .to(0.1, {
//                             x: d,
//                             y: p
//                         })
//                         .call(function () {
//                             if (s > 0) {
//                                 e(s, (n -= 1));
//                             } else {
//                                 t.moveindex = n + 1;
//                                 t.scheduleOnce(function () {
//                                     t.ismove = !0;
//                                 }, 0.1);
//                             }
//                         })
//                         .start();
//                 } else {
//                     t.moveindex = n + 1;
//                 }
//             })(e, o);
//         }
//     };
//     t.prototype.beAttack = function (e, t) {
//         if (void 0 === t) {
//             t = !1;
//         }
//         if (!this.isDie) {
//             this.ohterbullet = e;
//             var o = e.getBulletAttack(this);
//             var n = $buffMag.BuffMgr.addPlayerAttack(this, e.attackfang);
//             var i = $buffMag.BuffMgr.getMosterBombJiaCheng(this);
//             var a = 0;
//             if (2 == e.bulletId) {
//                 a = $buffMag.BuffMgr.getMosterBombCountHangHai(this);
//             }
//             var r = 0;
//             if (this.isXiGuaBomb) {
//                 r = $buffMag.BuffMgr.getMosterBombZengShang();
//             }
//             o += o * (n + i + a + r);
//             o += $buffMag.BuffMgr.getAttackGuding(e.attackfang);
//             this.playBeHitEff();
//             var c = 1;
//             if (e.isbaoji) {
//                 c = 2;
//             }
//             if (2 == e.bulletId || t) {
//                 c = 5;
//             }
//             this.jianxue(o, c, e.attackfang);
//         }
//     };
//     t.prototype.jianxue = function (e, t, o) {
//         if (this.nowHuDunNode) {
//             var n = this.nowHuDunNode.getComponent($uI_HuDun.default);
//             n.subXueLiang(e);
//             if (n.xuelinag < 0) {
//                 this.nowHuDunNode = null;
//             }
//         } else {
//             e = $buffMag.BuffMgr.getMosterAllShangHai(e);
//             this.mosterXueTiao.subXue(e);
//             this.xueliang -= e;
//             this.updateXueTiao();
//         }
//         var i = this.auto_ui.node_piaozipos;
//         if (o && o.playerId) {
//             $gameGlobalVariable.GameGlobalVariable.jiluAttack(o.playerId, e);
//         }
//         $eventManager.EventMgr.dispatchEvent(
//             $evenType.EVENT_TYPE.Game_ShangHai_FeiZi,
//             e,
//             i.convertToWorldSpaceAR(cc.v2()),
//             null,
//             t
//         );
//     };
//     t.prototype.fujiaAttack = function (e, t, o) {
//         if (!this.isDie) {
//             this.ohterbullet = o;
//             this.playBeHitEff();
//             this.jianxue(e, t, o);
//         }
//     };
//     t.prototype.playBeHitEff = function () {
//         var e = this.node.children[0].getChildByName("item").getComponent(cc.Sprite);
//         var t = {
//             value: 0
//         };
//         cc.tween(t)
//             .to(
//                 0.1,
//                 {
//                     value: 1
//                 },
//                 {
//                     onUpdate: function () {
//                         e.getMaterial(0).setProperty("u_rate", t.value);
//                     }
//                 }
//             )
//             .call(function () {
//                 e.getMaterial(0).setProperty("u_rate", t.value);
//             })
//             .start();
//     };
//     t.prototype.nowspeed = function () {
//         var e = 0;
//         if (this.isdongjie) {
//             e = 0;
//         } else {
//             {
//                 var t = 0.3 * this.mosterspeed;
//                 var o = $buffMag.BuffMgr.getNowSpeedBiLi();
//                 if (t > (e = this.mosterspeed - this.mosterspeed * (this.bingdongjianshu + o))) {
//                     e = t;
//                 }
//             }
//         }
//         return e * $gameGlobalVariable.GameGlobalVariable.jiasuState;
//     };
//     t.prototype.resetState = function () {
//         this.isjianshu = !1;
//         this.isdongjie = !1;
//         this.iszhongdu = !1;
//         this.isliuxue = !1;
//         this.isransao = !1;
//         this.dushan = 0;
//         this.bingdongjianshu = 0;
//     };
//     t.prototype.setJianShu = function (e, t, o) {
//         if (!(this.isjianshu && !$buffMag.BuffMgr.getDieJia(o))) {
//             this.diejiacount += 1;
//             if (this.diejiacount >= 3) {
//                 this.diejiacount = 3;
//             }
//             this.unschedule(this.resetValueBingDong);
//             this.addBingEff();
//             this.isjianshu = !0;
//             this.bingdongjianshu = (e / 100) * this.diejiacount;
//             this.scheduleOnce(this.resetValueBingDong, t);
//             this.setDongImg(!0, this.diejiacount);
//             $logManager.LogMgr.debug("冰冻减速效益", this.bingdongjianshu);
//         }
//     };
//     t.prototype.addDuEff = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             return __generator(this, function (t) {
//                 switch (t.label) {
//                     case 0:
//                         this.zhongduNode = $nodePoolMag.NodePoolMag.instance.getNode("zhongdu");
//                         return this.zhongduNode
//                             ? [3, 2]
//                             : [
//                                   4,
//                                   this._loadRes($bundleConfig.BundleNames.Game, "prefabs/effpre/UI_ZhongDu", cc.Prefab)
//                               ];
//                     case 1:
//                         e = t.sent();
//                         $nodePoolMag.NodePoolMag.instance.createNodeCount("zhongdu", 1, e);
//                         this.zhongduNode = $nodePoolMag.NodePoolMag.instance.getNode("zhongdu");
//                         t.label = 2;
//                     case 2:
//                         this.zhongduNode.x = 0;
//                         this.zhongduNode.y = 0;
//                         $gameGlobalVariable.GameGlobalVariable.effNode.addChild(this.zhongduNode);
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.cleanDuEff = function () {
//         if (this.zhongduNode) {
//             $nodePoolMag.NodePoolMag.instance.recycleNode("zhongdu", this.zhongduNode);
//             this.zhongduNode = null;
//         }
//     };
//     t.prototype.addBingEff = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             return __generator(this, function () {
//                 return [2];
//             });
//         });
//     };
//     t.prototype.updateEff = function () {
//         if (this.zhongduNode) {
//             this.zhongduNode.x = this.node.x;
//             this.zhongduNode.y = this.node.y;
//         }
//         if (this.dongjieNode) {
//             this.dongjieNode.x = this.node.x;
//             this.dongjieNode.y = this.node.y;
//         }
//     };
//     t.prototype.cleanBingEff = function () {
//         if (this.bingdongNode) {
//             $nodePoolMag.NodePoolMag.instance.recycleNode("bingshuang", this.bingdongNode);
//             this.bingdongNode = null;
//         }
//     };
//     t.prototype.addDongjieEff = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             return __generator(this, function (t) {
//                 switch (t.label) {
//                     case 0:
//                         if (this.isdongjie) {
//                             return [2];
//                         } else {
//                             return (
//                                 $audioManager.AudioMgr.playEffect("sound/冻结", !1, $bundleConfig.BundleNames.Game),
//                                 (this.dongjieNode = $nodePoolMag.NodePoolMag.instance.getNode("dongjie")),
//                                 this.dongjieNode
//                                     ? [3, 2]
//                                     : [
//                                           4,
//                                           this._loadRes(
//                                               $bundleConfig.BundleNames.Game,
//                                               "prefabs/effpre/UI_BingDong",
//                                               cc.Prefab
//                                           )
//                                       ]
//                             );
//                         }
//                     case 1:
//                         e = t.sent();
//                         $nodePoolMag.NodePoolMag.instance.createNodeCount("dongjie", 1, e);
//                         this.dongjieNode = $nodePoolMag.NodePoolMag.instance.getNode("dongjie");
//                         t.label = 2;
//                     case 2:
//                         this.dongjieNode.x = 0;
//                         this.dongjieNode.y = 0;
//                         $gameGlobalVariable.GameGlobalVariable.effNode.addChild(this.dongjieNode);
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.cleanDongjieEff = function () {
//         if (this.dongjieNode) {
//             $nodePoolMag.NodePoolMag.instance.recycleNode("dongjie", this.dongjieNode);
//             this.dongjieNode = null;
//         }
//     };
//     t.prototype.addLiuXueEff = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             return __generator(this, function (t) {
//                 switch (t.label) {
//                     case 0:
//                         if (this.isliuxue) {
//                             return [2];
//                         } else {
//                             return this.liuxueContentNode
//                                 ? ((this.liuxueNode = $nodePoolMag.NodePoolMag.instance.getNode("liuxue")),
//                                   this.liuxueNode
//                                       ? [3, 2]
//                                       : [
//                                             4,
//                                             this._loadRes(
//                                                 $bundleConfig.BundleNames.Game,
//                                                 "prefabs/effpre/UI_LiuXue",
//                                                 cc.Prefab
//                                             )
//                                         ])
//                                 : [3, 3];
//                         }
//                     case 1:
//                         e = t.sent();
//                         $nodePoolMag.NodePoolMag.instance.createNodeCount("liuxue", 1, e);
//                         this.liuxueNode = $nodePoolMag.NodePoolMag.instance.getNode("liuxue");
//                         t.label = 2;
//                     case 2:
//                         this.liuxueNode.x = 0;
//                         this.liuxueNode.y = 0;
//                         this.liuxueNode.width = this.liuxueContentNode.width;
//                         this.liuxueNode.height = this.liuxueContentNode.height;
//                         this.liuxueContentNode.addChild(this.liuxueNode);
//                         t.label = 3;
//                     case 3:
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.cleanLiuXueEff = function () {
//         if (this.liuxueNode) {
//             $nodePoolMag.NodePoolMag.instance.recycleNode("liuxue", this.liuxueNode);
//             this.liuxueNode = null;
//         }
//     };
//     t.prototype.setDongImg = function (e, t) {
//         return __awaiter(this, void 0, void 0, function () {
//             var o;
//             return __generator(this, function (n) {
//                 switch (n.label) {
//                     case 0:
//                         if (this.isDie) {
//                             return [2];
//                         } else {
//                             return e
//                                 ? ($gameGlobalVariable.GameGlobalVariable.playHitJianShu(),
//                                   (this.node.getChildByName("dongImg").active = !0),
//                                   [
//                                       4,
//                                       this._loadRes($bundleConfig.BundleNames.Common, "res/player/" + t, cc.SpriteFrame)
//                                   ])
//                                 : [3, 2];
//                         }
//                     case 1:
//                         o = n.sent();
//                         this.node.getChildByName("dongImg").getComponent(cc.Sprite).spriteFrame = o;
//                         return [3, 3];
//                     case 2:
//                         this.node.getChildByName("dongImg").active = !1;
//                         n.label = 3;
//                     case 3:
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.onSpeedJian = function (e, t) {
//         this.nowbuffatackplay = t;
//         switch (e.buffefftype) {
//             case 2:
//                 var o = $buffMag.BuffMgr.getDieJia(t);
//                 if (!(this.isjianshu && !o)) {
//                     this.diejiacount += 1;
//                     if (this.diejiacount >= 3) {
//                         this.diejiacount = 3;
//                     }
//                     this.unschedule(this.resetValueBingDong);
//                     this.addBingEff();
//                     this.isjianshu = !0;
//                     this.jianshutime = e.bufftime;
//                     this.bingdongjianshu = (e.value[0] / 100) * this.diejiacount;
//                     this.scheduleOnce(this.resetValueBingDong, e.bufftime);
//                     this.setDongImg(!0, this.diejiacount);
//                     $logManager.LogMgr.debug("冰冻减速效益", this.bingdongjianshu);
//                 }
//                 break;
//             case 5:
//                 $excel.Excel.shuiguoguaiwu(this.mosterId);
//                 if (Math.random() <= e.probability / 100) {
//                     if (this.isdongjie) {
//                         return;
//                     }
//                     this.addDongjieEff();
//                     this.isdongjie = !0;
//                     this.dongjietime = e.bufftime;
//                     $logManager.LogMgr.debug("冻结效益", this.isdongjie);
//                 }
//                 break;
//             case 1:
//                 this.dushan = e.value[0] / 100;
//                 if (this.iszhongdu) {
//                     return;
//                 }
//                 this.addDuEff();
//                 this.dushangplayer = t;
//                 this.iszhongdu = !0;
//                 this.zhongdutime = e.bufftime;
//                 break;
//             case 22:
//                 if (this.isliuxue) {
//                     return;
//                 }
//                 this.addLiuXueEff();
//                 this.liuxueshang = e.value[0] + e.value[0] * $buffMag.BuffMgr.getLiuXueJiaCheng(t);
//                 this.isliuxue = !0;
//                 this.liuxuetime = e.bufftime;
//                 break;
//             case 24:
//                 if (this.isransao) {
//                     return;
//                 }
//                 this.ransaoshang = e.value[0];
//                 this.isransao = !0;
//                 this.ransaotime = e.bufftime;
//         }
//     };
//     t.prototype.resetValueBingDong = function () {
//         this.bingdongjianshu = 0;
//         this.isjianshu = !1;
//         this.diejiacount = 0;
//         this.cleanBingEff();
//         this.setDongImg(!1, 0);
//     };
//     t.prototype.resetDongJie = function () {
//         this.isdongjie = !1;
//         this.cleanDongjieEff();
//     };
//     t.prototype.zhongduXue = function () {
//         var e = $buffMag.BuffMgr.getDuShang();
//         var t = $buffMag.BuffMgr.playAttackJiaCheng(this.dushangplayer, this.dushangplayer.sgattack, 1) * this.dushan;
//         if (e) {
//             t += t * (e.value[0] / 100);
//         }
//         this.jianxue(t, 3, this.nowbuffatackplay);
//     };
//     t.prototype.liuxueXue = function () {
//         this.jianxue(this.liuxueshang, 4, this.nowbuffatackplay);
//     };
//     t.prototype.ranshaoXue = function () {
//         this.jianxue(this.ransaoshang, 5, this.nowbuffatackplay);
//     };
//     t.prototype.onUpdate = function (e) {
//         this.moveBu();
//         this.updateEff();
//         if (this.isransao) {
//             this.ransaotimeleiji += e;
//             if (this.ransaotimeleiji >= 1) {
//                 this.ranshaoXue();
//                 this.ransaotime -= 1;
//                 if (this.ransaotime <= 0) {
//                     this.isransao = !1;
//                 }
//                 this.ransaotimeleiji = 0;
//             }
//         }
//         if (this.iszhongdu) {
//             this.dutimeleiji += e;
//             if (this.dutimeleiji >= 1) {
//                 this.zhongduXue();
//                 this.zhongdutime -= 1;
//                 if (this.zhongdutime <= 0) {
//                     this.cleanDuEff();
//                     this.iszhongdu = !1;
//                 }
//                 this.dutimeleiji = 0;
//             }
//         }
//         if (this.isliuxue) {
//             this.liutimeleiji += e;
//             if (this.liutimeleiji >= 1) {
//                 this.liuxueXue();
//                 this.liuxuetime -= 1;
//                 if (this.liuxuetime <= 0) {
//                     this.cleanLiuXueEff();
//                     this.isliuxue = !1;
//                 }
//                 this.liutimeleiji = 0;
//             }
//         }
//         if (this.isdongjie) {
//             this.dongjieleiji += e;
//             if (this.dongjieleiji >= 1) {
//                 this.dongjietime -= 1;
//                 if (this.dongjietime <= 0) {
//                     this.resetDongJie();
//                 }
//                 this.dongjieleiji = 0;
//             }
//         }
//         if (this.iszhaohuan) {
//             this.zhaohuantimeleiji += e;
//             if (this.zhaohuantimeleiji >= 1) {
//                 $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_ZhaoHuan_Moster, this);
//                 this.zhaohuantimeleiji = 0;
//             }
//         }
//     };
//     __decorate([x($uI_MosterLogic_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     __decorate([x()], t.prototype, "mosterId", void 0);
//     __decorate([x(cc.Node)], t.prototype, "hunmoNode", void 0);
//     __decorate([x($uI_MosterXueTiao.default)], t.prototype, "mosterXueTiao", void 0);
//     return __decorate([E], t);
// })($resKeeper.default);
// exports.default = B;


// import UIMonsterLogicUIBindings from "./UI_MosterLogic_UIBindings";
// import ResKeeper from "./ResKeeper";
// import {EventMgrInstance} from "./EventManager";
// import {EVENT_TYPE} from "./EvenType";
// import {NodePoolMag} from "./NodePoolMag";
// import {BundleNames} from "./BundleConfig";
// import Shield from "./UI_HuDun";
// import UI_MosterXueTiao from "./UI_MosterXueTiao";
// import { LogMgr } from "./LogManager";
// import {GameDataMgr} from "./GameDataManager";
// import { GameGlobalVariable } from "./GameGlobalVariable";
// import { AudioMgr } from "./AudioManager";
// import { Excel } from './Excel';
// import { BuffMgr } from './BuffMag';

// const { ccclass, property } = cc._decorator;

// /**
//  * 建议类名：MonsterLogic
//  */
// @ccclass
// export default class UI_MosterLogic extends ResKeeper {
//     @property(UIMonsterLogicUIBindings)
//     auto_ui: UIMonsterLogicUIBindings = null;

//     @property
//     mosterId: number = 1;

//     @property(cc.Node)
//     hunmoNode: cc.Node = null;

//     @property(UI_MosterXueTiao)
//     mosterXueTiao: UI_MosterXueTiao = null;

//     xueliang: number = 0;
//     maxxueliang: number = 0;
//     mosterspeed: number = 0;
//     defy: number = 999999;
//     liuxueContentNode: cc.Node = null;
//     zhengshangNode: cc.Node = null;
//     nowmosterdata: any = null;
//     paths: cc.Node = null;
//     nowtexindex: number = 0;
//     twmove: cc.Tween = null;
//     nowHuDunNode: cc.Node = null;
//     iszhaohuan: boolean = false;
//     zhaohuantime: number = 100;
//     isXiGuaBomb: boolean = false;
//     isDie: boolean = false;
//     ohterbullet: any = null;
//     zhongduNode: cc.Node = null;
//     bingdongNode: cc.Node = null;
//     dongjieNode: cc.Node = null;
//     liuxueNode: cc.Node = null;
//     bingdongjianshu: number = 0;
//     isjianshu: boolean = false;
//     jianshutime: number = 0;
//     isdongjie: boolean = false;
//     dongjietime: number = 0;
//     iszhongdu: boolean = false;
//     dushan: number = 0;
//     zhongdutime: number = 0;
//     isliuxue: boolean = false;
//     liuxueshang: number = 0;
//     liuxuetime: number = 0;
//     isransao: boolean = false;
//     ransaoshang: number = 0;
//     ransaotime: number = 0;
//     diejiacount: number = 0;
//     dushangplayer: any = null;
//     nowbuffatackplay: any = null;
//     ismove: boolean = false;
//     moveindex: number = 0;
//     tesofftime: number = 0;
//     dutimeleiji: number = 0;
//     liutimeleiji: number = 0;
//     ransaotimeleiji: number = 0;
//     jiansuleiji: number = 0;
//     dongjieleiji: number = 0;
//     zhaohuantimeleiji: number = 0;

//     /**
//      * 建议方法名：onComponentEnabled
//      */
//     onEnable() {
//         this.node.children.forEach(child => {
//             child.active = true;
//         });

//         if (this.defy !== 999999) {
//             this.hunmoNode.y = this.defy;
//         } else {
//             this.defy = this.hunmoNode.y;
//         }

//         this.hunmoNode.active = false;
//         this.node.getChildByName("dongImg").active = false;
//         this.liuxueContentNode = this.node.getChildByName("liuxueNode");
//         this.zhengshangNode = this.node.getChildByName("zhengshang");
//         this.zhengshangNode.active = false;
//     }

//     /**
//      * 建议方法名：onComponentDisabled
//      */
//     onDisable() {
//         if (this.nowHuDunNode) {
//             NodePoolMag.instance.recycleNode("hudun", this.nowHuDunNode);
//             this.nowHuDunNode = null;
//         }

//         BuffMgr.cleanMosterBombCount(this);
//         this.cleanDuEff();
//         this.cleanBingEff();
//         this.cleanDongjieEff();
//         this.cleanLiuXueEff();
//         this.cleanXiGuaBomb();
//         this.unscheduleAllCallbacks();
//     }

//     /**
//      * 建议方法名：activateXiGuaBomb
//      */
//     async setIsXiGuaBomb() {
//         if (!this.isXiGuaBomb && !this.isDie) {
//             this.isXiGuaBomb = true;
//             this.zhengshangNode.active = true;
//         }
//     }

//     /**
//      * 建议方法名：deactivateXiGuaBomb
//      */
//     cleanXiGuaBomb() {
//         this.zhengshangNode.active = false;
//     }

//     /**
//      * 建议方法名：initializeMonsterInfo
//      * @param e 怪物ID
//      * @param t 路径节点
//      * @param o 纹理索引
//      * @param n 关卡数据
//      * @param i 移动索引
//      */
//     async setMosterInfo(e: number, t: cc.Node, o: number, n: any, i: number = 1) {
//         this.isDie = false;
//         this.isXiGuaBomb = false;
//         this.nowtexindex = o;
//         const monsterData = Excel.shuiguoguaiwu(e);
//         this.nowmosterdata = monsterData;
//         this.mosterspeed = this.nowmosterdata.mosterspeed / 60;
//         this.xueliang = this.nowmosterdata.mosterxue;

//         let healthMultiplier = 1;
//         if (GameGlobalVariable.isTeShuLevel() === 1) {
//             const maxLevel = GameDataMgr.getNowMaxLevel();
//             const levelData = Excel.shuiguoguanqia(maxLevel);
//             const bossId = levelData.levelboshuid[levelData.levelboshuid.length - 1];
//             const bossData = Excel.shuiguoboshu(bossId);
//             healthMultiplier = bossData.mosterjiaxue;
//         }

//         if (n) {
//             this.xueliang = this.nowmosterdata.mosterxue * n.mosterjiaxue * healthMultiplier;
//         }

//         this.maxxueliang = this.xueliang;
//         this.mosterXueTiao.initXue(this.maxxueliang);
//         this.moveindex = i;
//         this.paths = t;
//         this.updateXueTiao();
//         this.ismove = true;
//         this.node.opacity = 0;

//         cc.tween(this.node)
//             .to(0.2, { opacity: 255 })
//             .start();

//         const children = this.auto_ui.node_piaozipos.children;
//         for (let j = 0; j < children.length; j++) {
//             const child = children[0];
//             NodePoolMag.instance.recycleNode("piaozi", child);
//         }

//         this.twmove = cc.tween(this.node.children[0])
//             .to(0.25, { scaleY: 0.9 })
//             .to(0.25, { scaleY: 1 });

//         cc.tween(this.node.children[0]).repeatForever(this.twmove).start();
//     }

//     /**
//      * 建议方法名：addShield
//      */
//     async addHuDun() {
//         this.nowHuDunNode = NodePoolMag.instance.getNode("hudun");
//         if (!this.nowHuDunNode) {
//             const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_HuDun", cc.Prefab);
//             NodePoolMag.instance.createNodeCount("hudun", 1, prefab);
//             this.nowHuDunNode = NodePoolMag.instance.getNode("hudun");
//         }

//         this.auto_ui.node_hudunnode.addChild(this.nowHuDunNode);
//         this.nowHuDunNode.getComponent(Shield).initHuDu(100);
//         this.iszhaohuan = false;
//     }

//     /**
//      * 建议方法名：updateHealthBar
//      */
//     updateXueTiao() {
//         if (this.xueliang <= 0) {
//             this.isDieMoster();
//         }
//     }

//     /**
//      * 建议方法名：handleMonsterDeath
//      * @param e 死亡类型
//      */
//     isDieMoster(e: number = 1) {
//         if (!this.isDie) {
//             BuffMgr.cleanMosterDieJia(this);
//             BuffMgr.cleanMosterBomb(this.node.uuid);

//             const poisonEffect = BuffMgr.getDuWu();
//             if (this.iszhongdu && poisonEffect) {
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_CreateDuWu, this, poisonEffect, this.dushangplayer);
//             }

//             if (this.ohterbullet && this.ohterbullet.attackfang) {
//                 BuffMgr.setBombShanHai(this.ohterbullet.attackfang, this);
//             }

//             this.node.children.forEach(child => {
//                 child.active = false;
//             });

//             this.hunmoNode.active = true;
//             this.hunmoNode.opacity = 255;

//             cc.tween(this.hunmoNode)
//                 .to(0.5, { y: this.hunmoNode.y + 100 })
//                 .to(0.1, { opacity: 0 })
//                 .call(() => {
//                     this.node.stopAllActions();
//                     this.unscheduleAllCallbacks();
//                     this.resetState();
//                     NodePoolMag.instance.recycleNode("moster_" + this.mosterId, this.node);
//                 })
//                 .start();

//             this.isDie = true;
//             this.ismove = false;

//             if (e === 1) {
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Moster_DIE, { moster: this.mosterId });
//             }
//         }
//     }

//     /**
//      * 建议方法名：moveStep
//      */
//     moveBu() {
//         if (this.ismove) {
//             const targetNode = this.paths.children[this.moveindex];
//             if (!targetNode) {
//                 this.isDieMoster(2);
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Moster_Attack, { mosterId: this.mosterId });
//                 return;
//             }

//             const targetX = targetNode.x;
//             const targetY = targetNode.y;

//             if (this.moveindex === 0) {
//                 this.node.setPosition(targetX, targetY);
//                 this.moveindex += 1;
//             } else {
//                 const direction = cc.Vec2.subtract(cc.v2(), cc.v2(targetX, targetY), this.node.getPosition());
//                 const angle = Math.atan2(direction.y, direction.x);
//                 const distance = cc.Vec2.distance(this.node.getPosition(), cc.v2(targetX, targetY));

//                 this.node.x += Math.cos(angle) * this.nowspeed();
//                 this.node.y += Math.sin(angle) * this.nowspeed();

//                 if (distance < 5) {
//                     this.moveindex += 1;
//                 }
//             }
//         }
//     }

//     /**
//      * 建议方法名：getNearbyMonsterNodes
//      * @param e 距离
//      * @returns 附近的怪物节点数组
//      */
//     getNowMosterNode(e: number): cc.Node[] {
//         const siblings = this.node.parent.children;
//         const nearbyNodes: cc.Node[] = [];

//         for (let i = 0; i < siblings.length; i++) {
//             const sibling = siblings[i];
//             let distance = cc.Vec2.distance(sibling.getPosition(), this.node.getPosition());
//             distance -= sibling.width / 2 + this.node.width / 2;

//             if (distance <= e) {
//                 nearbyNodes.push(sibling);
//             }
//         }

//         return nearbyNodes;
//     }

//     /**
//      * 建议方法名：knockback
//      * @param e 距离
//      */
//     backTui(e: number) {
//         if (this.moveindex >= 2) {
//             this.ismove = false;
//             let targetIndex = this.moveindex - 1;
//             if (targetIndex < 0) {
//                 targetIndex = 0;
//             }

//             const moveBack = (remainingDistance: number, index: number) => {
//                 const targetNode = this.paths.children[index];
//                 if (targetNode) {
//                     const targetX = targetNode.x;
//                     const targetY = targetNode.y;
//                     const distance = cc.Vec2.distance(this.node.getPosition(), cc.v2(targetX, targetY));
//                     let remaining = 0;

//                     if (remainingDistance > distance) {
//                         remaining = remainingDistance - distance;
//                         remainingDistance = distance;
//                     }

//                     const direction = cc.Vec2.subtract(cc.v2(), cc.v2(targetX, targetY), this.node.getPosition());
//                     const angle = Math.atan2(direction.y, direction.x);
//                     const newX = this.node.x + Math.cos(angle) * remainingDistance;
//                     const newY = this.node.y + Math.sin(angle) * remainingDistance;

//                     cc.tween(this.node)
//                         .to(0.1, { x: newX, y: newY })
//                         .call(() => {
//                             if (remaining > 0) {
//                                 moveBack(remaining, index - 1);
//                             } else {
//                                 this.moveindex = index + 1;
//                                 this.scheduleOnce(() => {
//                                     this.ismove = true;
//                                 }, 0.1);
//                             }
//                         })
//                         .start();
//                 } else {
//                     this.moveindex = index + 1;
//                 }
//             };

//             moveBack(e, targetIndex);
//         }
//     }

//     /**
//      * 建议方法名：receiveAttack
//      * @param e 子弹
//      * @param t 是否暴击
//      */
//     beAttack(e: any, t: boolean = false) {
//         if (!this.isDie) {
//             this.ohterbullet = e;
//             let damage = e.getBulletAttack(this);
//             const playerAttackBonus = BuffMgr.addPlayerAttack(this, e.attackfang);
//             const bombBonus = BuffMgr.getMosterBombJiaCheng(this);
//             let additionalDamage = 0;

//             if (e.bulletId === 2) {
//                 additionalDamage = BuffMgr.getMosterBombCountHangHai(this);
//             }

//             let watermelonBonus = 0;
//             if (this.isXiGuaBomb) {
//                 watermelonBonus = BuffMgr.getMosterBombZengShang();
//             }

//             damage += damage * (playerAttackBonus + bombBonus + additionalDamage + watermelonBonus);
//             damage += BuffMgr.getAttackGuding(e.attackfang);

//             this.playBeHitEff();

//             let damageType = 1;
//             if (e.isbaoji) {
//                 damageType = 2;
//             }
//             if (e.bulletId === 2 || t) {
//                 damageType = 5;
//             }

//             this.jianxue(damage, damageType, e.attackfang);
//         }
//     }

//     /**
//      * 建议方法名：reduceHealth
//      * @param e 伤害值
//      * @param t 伤害类型
//      * @param o 攻击方
//      */
//     jianxue(e: number, t: number, o: any) {
//         if (this.nowHuDunNode) {
//             const shieldComponent = this.nowHuDunNode.getComponent(Shield);
//             shieldComponent.subXueLiang(e);

//             if (shieldComponent.xuelinag < 0) {
//                 this.nowHuDunNode = null;
//             }
//         } else {
//             e = BuffMgr.getMosterAllShangHai(e);
//             this.mosterXueTiao.subXue(e);
//             this.xueliang -= e;
//             this.updateXueTiao();
//         }

//         const hitPosition = this.auto_ui.node_piaozipos;
//         if (o && o.playerId) {
//             GameGlobalVariable.jiluAttack(o.playerId, e);
//         }

//         EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_ShangHai_FeiZi, e, hitPosition.convertToWorldSpaceAR(cc.v2()), null, t);
//     }

//     /**
//      * 建议方法名：applyAdditionalAttack
//      * @param e 伤害值
//      * @param t 伤害类型
//      * @param o 子弹
//      */
//     fujiaAttack(e: number, t: number, o: any) {
//         if (!this.isDie) {
//             this.ohterbullet = o;
//             this.playBeHitEff();
//             this.jianxue(e, t, o);
//         }
//     }

//     /**
//      * 建议方法名：playHitEffect
//      */
//     playBeHitEff() {
//         const sprite = this.node.children[0].getChildByName("item").getComponent(cc.Sprite);
//         const tweenValue = { value: 0 };

//         cc.tween(tweenValue)
//             .to(0.1, { value: 1 }, {
//                 onUpdate: () => {
//                     sprite.getMaterial(0).setProperty("u_rate", tweenValue.value);
//                 }
//             })
//             .call(() => {
//                 sprite.getMaterial(0).setProperty("u_rate", tweenValue.value);
//             })
//             .start();
//     }

//     /**
//      * 建议方法名：getCurrentSpeed
//      * @returns 当前速度
//      */
//     nowspeed(): number {
//         let speed = 0;

//         if (this.isdongjie) {
//             speed = 0;
//         } else {
//             const minSpeed = 0.3 * this.mosterspeed;
//             const speedReduction = BuffMgr.getNowSpeedBiLi();
//             speed = this.mosterspeed - this.mosterspeed * (this.bingdongjianshu + speedReduction);

//             if (speed < minSpeed) {
//                 speed = minSpeed;
//             }
//         }

//         return speed * GameGlobalVariable.jiasuState;
//     }

// /**
//      * 建议方法名：resetMonsterState
//      */
//     resetState() {
//         this.isjianshu = false;
//         this.isdongjie = false;
//         this.iszhongdu = false;
//         this.isliuxue = false;
//         this.isransao = false;
//         this.dushan = 0;
//         this.bingdongjianshu = 0;
//     }

//     /**
//      * 建议方法名：applySlowEffect
//      * @param e 减速值
//      * @param t 持续时间
//      * @param o 攻击方
//      */
//     setJianShu(e: number, t: number, o: any) {
//         if (!(this.isjianshu && !BuffMgr.getDieJia(o))) {
//             this.diejiacount += 1;
//             if (this.diejiacount >= 3) {
//                 this.diejiacount = 3;
//             }
//             this.unschedule(this.resetValueBingDong);
//             this.addBingEff();
//             this.isjianshu = true;
//             this.bingdongjianshu = (e / 100) * this.diejiacount;
//             this.scheduleOnce(this.resetValueBingDong, t);
//             this.setDongImg(true, this.diejiacount);
//             LogMgr.debug("冰冻减速效益", this.bingdongjianshu);
//         }
//     }

//     /**
//      * 建议方法名：addPoisonEffect
//      */
//     async addDuEff() {
//         this.zhongduNode = NodePoolMag.instance.getNode("zhongdu");
//         if (!this.zhongduNode) {
//             const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_ZhongDu", cc.Prefab);
//             NodePoolMag.instance.createNodeCount("zhongdu", 1, prefab);
//             this.zhongduNode = NodePoolMag.instance.getNode("zhongdu");
//         }

//         this.zhongduNode.x = 0;
//         this.zhongduNode.y = 0;
//         GameGlobalVariable.effNode.addChild(this.zhongduNode);
//     }

//     /**
//      * 建议方法名：removePoisonEffect
//      */
//     cleanDuEff() {
//         if (this.zhongduNode) {
//             NodePoolMag.instance.recycleNode("zhongdu", this.zhongduNode);
//             this.zhongduNode = null;
//         }
//     }

//     /**
//      * 建议方法名：addFreezeEffect
//      */
//     async addBingEff() {
//         // 这里可以添加冰冻效果的实现
//     }

//     /**
//      * 建议方法名：updateEffects
//      */
//     updateEff() {
//         if (this.zhongduNode) {
//             this.zhongduNode.setPosition(this.node.getPosition());
//         }
//         if (this.dongjieNode) {
//             this.dongjieNode.setPosition(this.node.getPosition());
//         }
//     }

//     /**
//      * 建议方法名：removeFreezeEffect
//      */
//     cleanBingEff() {
//         if (this.bingdongNode) {
//             NodePoolMag.instance.recycleNode("bingshuang", this.bingdongNode);
//             this.bingdongNode = null;
//         }
//     }

//     /**
//      * 建议方法名：addFrozenEffect
//      */
//     async addDongjieEff() {
//         if (this.isdongjie) {
//             return;
//         }

//         AudioMgr.playEffect("sound/冻结", false, BundleNames.Game);
//         this.dongjieNode = NodePoolMag.instance.getNode("dongjie");
//         if (!this.dongjieNode) {
//             const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_BingDong", cc.Prefab);
//             NodePoolMag.instance.createNodeCount("dongjie", 1, prefab);
//             this.dongjieNode = NodePoolMag.instance.getNode("dongjie");
//         }

//         this.dongjieNode.x = 0;
//         this.dongjieNode.y = 0;
//         GameGlobalVariable.effNode.addChild(this.dongjieNode);
//     }

//     /**
//      * 建议方法名：removeFrozenEffect
//      */
//     cleanDongjieEff() {
//         if (this.dongjieNode) {
//             NodePoolMag.instance.recycleNode("dongjie", this.dongjieNode);
//             this.dongjieNode = null;
//         }
//     }

//     /**
//      * 建议方法名：addBleedEffect
//      */
//     async addLiuXueEff() {
//         if (this.isliuxue) {
//             return;
//         }

//         if (this.liuxueContentNode) {
//             this.liuxueNode = NodePoolMag.instance.getNode("liuxue");
//             if (!this.liuxueNode) {
//                 const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_LiuXue", cc.Prefab);
//                 NodePoolMag.instance.createNodeCount("liuxue", 1, prefab);
//                 this.liuxueNode = NodePoolMag.instance.getNode("liuxue");
//             }

//             this.liuxueNode.x = 0;
//             this.liuxueNode.y = 0;
//             this.liuxueNode.width = this.liuxueContentNode.width;
//             this.liuxueNode.height = this.liuxueContentNode.height;
//             this.liuxueContentNode.addChild(this.liuxueNode);
//         }
//     }

//     /**
//      * 建议方法名：removeBleedEffect
//      */
//     cleanLiuXueEff() {
//         if (this.liuxueNode) {
//             NodePoolMag.instance.recycleNode("liuxue", this.liuxueNode);
//             this.liuxueNode = null;
//         }
//     }

//     /**
//      * 建议方法名：setFrozenImage
//      * @param e 是否显示
//      * @param t 图片索引
//      */
//     async setDongImg(e: boolean, t: number) {
//         if (this.isDie) {
//             return;
//         }

//         if (e) {
//             GameGlobalVariable.playHitJianShu();
//             this.node.getChildByName("dongImg").active = true;
//             const spriteFrame = await this._loadRes(BundleNames.Common, `res/player/${t}`, cc.SpriteFrame);
//             this.node.getChildByName("dongImg").getComponent(cc.Sprite).spriteFrame = spriteFrame;
//         } else {
//             this.node.getChildByName("dongImg").active = false;
//         }
//     }

//     /**
//      * 建议方法名：applySpeedReduction
//      * @param e Buff效果
//      * @param t 攻击方
//      */
//     onSpeedJian(e: any, t: any) {
//         this.nowbuffatackplay = t;

//         switch (e.buffefftype) {
//             case 2:
//                 const isStackable = BuffMgr.getDieJia(t);
//                 if (!(this.isjianshu && !isStackable)) {
//                     this.diejiacount += 1;
//                     if (this.diejiacount >= 3) {
//                         this.diejiacount = 3;
//                     }
//                     this.unschedule(this.resetValueBingDong);
//                     this.addBingEff();
//                     this.isjianshu = true;
//                     this.jianshutime = e.bufftime;
//                     this.bingdongjianshu = (e.value[0] / 100) * this.diejiacount;
//                     this.scheduleOnce(this.resetValueBingDong, e.bufftime);
//                     this.setDongImg(true, this.diejiacount);
//                     LogMgr.debug("冰冻减速效益", this.bingdongjianshu);
//                 }
//                 break;
//             case 5:
//                 Excel.shuiguoguaiwu(this.mosterId);
//                 if (Math.random() <= e.probability / 100) {
//                     if (this.isdongjie) {
//                         return;
//                     }
//                     this.addDongjieEff();
//                     this.isdongjie = true;
//                     this.dongjietime = e.bufftime;
//                     LogMgr.debug("冻结效益", this.isdongjie);
//                 }
//                 break;
//             case 1:
//                 this.dushan = e.value[0] / 100;
//                 if (this.iszhongdu) {
//                     return;
//                 }
//                 this.addDuEff();
//                 this.dushangplayer = t;
//                 this.iszhongdu = true;
//                 this.zhongdutime = e.bufftime;
//                 break;
//             case 22:
//                 if (this.isliuxue) {
//                     return;
//                 }
//                 this.addLiuXueEff();
//                 this.liuxueshang = e.value[0] + e.value[0] * BuffMgr.getLiuXueJiaCheng(t);
//                 this.isliuxue = true;
//                 this.liuxuetime = e.bufftime;
//                 break;
//             case 24:
//                 if (this.isransao) {
//                     return;
//                 }
//                 this.ransaoshang = e.value[0];
//                 this.isransao = true;
//                 this.ransaotime = e.bufftime;
//         }
//     }

//     /**
//      * 建议方法名：resetFreezeValue
//      */
//     resetValueBingDong() {
//         this.bingdongjianshu = 0;
//         this.isjianshu = false;
//         this.diejiacount = 0;
//         this.cleanBingEff();
//         this.setDongImg(false, 0);
//     }

//     /**
//      * 建议方法名：resetFrozenState
//      */
//     resetDongJie() {
//         this.isdongjie = false;
//         this.cleanDongjieEff();
//     }

//     /**
//      * 建议方法名：applyPoisonDamage
//      */
//     zhongduXue() {
//         const poisonDamage = BuffMgr.getDuShang();
//         let totalDamage = BuffMgr.playAttackJiaCheng(this.dushangplayer, this.dushangplayer.sgattack, 1) * this.dushan;

//         if (poisonDamage) {
//             totalDamage += totalDamage * (poisonDamage.value[0] / 100);
//         }

//         this.jianxue(totalDamage, 3, this.nowbuffatackplay);
//     }

//     /**
//      * 建议方法名：applyBleedDamage
//      */
//     liuxueXue() {
//         this.jianxue(this.liuxueshang, 4, this.nowbuffatackplay);
//     }

//     /**
//      * 建议方法名：applyBurnDamage
//      */
//     ranshaoXue() {
//         this.jianxue(this.ransaoshang, 5, this.nowbuffatackplay);
//     }

//     /**
//      * 建议方法名：updateComponent
//      * @param dt 时间增量
//      */
//     onUpdate(dt: number) {
//         this.moveBu();
//         this.updateEff();

//         if (this.isransao) {
//             this.ransaotimeleiji += dt;
//             if (this.ransaotimeleiji >= 1) {
//                 this.ranshaoXue();
//                 this.ransaotime -= 1;
//                 if (this.ransaotime <= 0) {
//                     this.isransao = false;
//                 }
//                 this.ransaotimeleiji = 0;
//             }
//         }

//         if (this.iszhongdu) {
//             this.dutimeleiji += dt;
//             if (this.dutimeleiji >= 1) {
//                 this.zhongduXue();
//                 this.zhongdutime -= 1;
//                 if (this.zhongdutime <= 0) {
//                     this.cleanDuEff();
//                     this.iszhongdu = false;
//                 }
//                 this.dutimeleiji = 0;
//             }
//         }

//         if (this.isliuxue) {
//             this.liutimeleiji += dt;
//             if (this.liutimeleiji >= 1) {
//                 this.liuxueXue();
//                 this.liuxuetime -= 1;
//                 if (this.liuxuetime <= 0) {
//                     this.cleanLiuXueEff();
//                     this.isliuxue = false;
//                 }
//                 this.liutimeleiji = 0;
//             }
//         }

//         if (this.isdongjie) {
//             this.dongjieleiji += dt;
//             if (this.dongjieleiji >= 1) {
//                 this.dongjietime -= 1;
//                 if (this.dongjietime <= 0) {
//                     this.resetDongJie();
//                 }
//                 this.dongjieleiji = 0;
//             }
//         }

//         if (this.iszhaohuan) {
//             this.zhaohuantimeleiji += dt;
//             if (this.zhaohuantimeleiji >= 1) {
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_ZhaoHuan_Moster, this);
//                 this.zhaohuantimeleiji = 0;
//             }
//         }
//     }
// }

import UIMonsterLogicUIBindings from "./UI_MosterLogic_UIBindings";
import ResKeeper from "./ResKeeper";
import { EventMgrInstance } from "./EventManager";
import { EVENT_TYPE } from "./EvenType";
import { NodePoolMag } from "./NodePoolMag";
import { BundleNames } from "./BundleConfig";
import ViewShield from "./UI_HuDun";
import ViewMosterXueTiao from "./UI_MosterXueTiao";
import { LogMgr } from "./LogManager";
import { GameDataMgr } from "./GameDataManager";
import { GameGlobalVariable } from "./GameGlobalVariable";
import { AudioMgr } from "./AudioManager";
import { Excel } from './Excel';
import { BuffMgr } from './BuffMag';

const { ccclass, property } = cc._decorator;

/**
 * 建议类名：MonsterLogic
 */
@ccclass
export default class ViewMosterLogic extends ResKeeper {
    @property(UIMonsterLogicUIBindings)
    auto_ui: UIMonsterLogicUIBindings = null;

    @property
    mosterId: number = 1;

    @property(cc.Node)
    hunmoNode: cc.Node = null;

    @property(ViewMosterXueTiao)
    mosterXueTiao: ViewMosterXueTiao = null;

    // 用于追踪怪物属性和状态的各种变量
    xueliang: number = 0;
    maxxueliang: number = 0;
    mosterspeed: number = 0;
    defy: number = 999999;
    liuxueContentNode: cc.Node = null;
    zhengshangNode: cc.Node = null;
    nowmosterdata: any = null;
    paths: cc.Node = null;
    nowtexindex: number = 0;
    twmove: cc.Tween = null;
    nowHuDunNode: cc.Node = null;
    iszhaohuan: boolean = false;
    zhaohuantime: number = 100;
    isXiGuaBomb: boolean = false;
    isDie: boolean = false;
    ohterbullet: any = null;
    zhongduNode: cc.Node = null;
    bingdongNode: cc.Node = null;
    dongjieNode: cc.Node = null;
    liuxueNode: cc.Node = null;
    bingdongjianshu: number = 0;
    isjianshu: boolean = false;
    jianshutime: number = 0;
    isdongjie: boolean = false;
    dongjietime: number = 0;
    iszhongdu: boolean = false;
    dushan: number = 0;
    zhongdutime: number = 0;
    isliuxue: boolean = false;
    liuxueshang: number = 0;
    liuxuetime: number = 0;
    isransao: boolean = false;
    ransaoshang: number = 0;
    ransaotime: number = 0;
    diejiacount: number = 0;
    dushangplayer: any = null;
    nowbuffatackplay: any = null;
    ismove: boolean = false;
    moveindex: number = 0;
    tesofftime: number = 0;
    dutimeleiji: number = 0;
    liutimeleiji: number = 0;
    ransaotimeleiji: number = 0;
    jiansuleiji: number = 0;
    dongjieleiji: number = 0;
    zhaohuantimeleiji: number = 0;

    /**
     * 建议方法名：onComponentEnabled
     */
    onEnable() {
        this.node.children.forEach(child => {
            child.active = true;
        });

        if (this.defy !== 999999) {
            this.hunmoNode.y = this.defy;
        } else {
            this.defy = this.hunmoNode.y;
        }

        this.hunmoNode.active = false;
        this.node.getChildByName("dongImg").active = false;
        this.liuxueContentNode = this.node.getChildByName("liuxueNode");
        this.zhengshangNode = this.node.getChildByName("zhengshang");
        this.zhengshangNode.active = false;
    }

    /**
     * 建议方法名：onComponentDisabled
     */
    onDisable() {
        if (this.nowHuDunNode) {
            NodePoolMag.instance.recycleNodeToPool("hudun", this.nowHuDunNode);
            this.nowHuDunNode = null;
        }

        BuffMgr.clearMonsterBombCount(this);
        this.removePoisonEffect();
        this.removeFreezeEffect();
        this.removeFrozenEffect();
        this.removeBleedEffect();
        this.deactivateXiGuaBomb();
        this.unscheduleAllCallbacks();
    }

    /**
     * 建议方法名：activateXiGuaBomb
     */
    async activateXiGuaBomb() {
        if (!this.isXiGuaBomb && !this.isDie) {
            this.isXiGuaBomb = true;
            this.zhengshangNode.active = true;
        }
    }

    /**
     * 建议方法名：deactivateXiGuaBomb
     */
    deactivateXiGuaBomb() {
        this.zhengshangNode.active = false;
    }

    /**
     * 建议方法名：initializeMonsterInfo
     * @param e 怪物ID
     * @param t 路径节点
     * @param o 纹理索引
     * @param n 关卡数据
     * @param i 移动索引
     */
    async initializeMonsterInfo(e: number, t: cc.Node, o: number, n: any, i: number = 1) {
        this.isDie = false;
        this.isXiGuaBomb = false;
        this.nowtexindex = o;
        const monsterData = Excel.shuiguoguaiwu(e);
        this.nowmosterdata = monsterData;
        this.mosterspeed = this.nowmosterdata.mosterspeed / 60;
        this.xueliang = this.nowmosterdata.mosterxue;

        let healthMultiplier = 1;
        if (GameGlobalVariable.isSpecialLevel() === 1) {
            const maxLevel = GameDataMgr.getCurrentMaxLevel();
            const levelData = Excel.shuiguoguanqia(maxLevel);
            const bossId = levelData.levelboshuid[levelData.levelboshuid.length - 1];
            const bossData = Excel.shuiguoboshu(bossId);
            healthMultiplier = bossData.mosterjiaxue;
        }

        if (n) {
            this.xueliang = this.nowmosterdata.mosterxue * n.mosterjiaxue * healthMultiplier;
        }

        this.maxxueliang = this.xueliang;
        this.mosterXueTiao.initializeBloodBar(this.maxxueliang);
        this.moveindex = i;
        this.paths = t;
        this.updateHealthBar();
        this.ismove = true;
        this.node.opacity = 0;

        cc.tween(this.node)
            .to(0.2, { opacity: 255 })
            .start();

        const children = this.auto_ui.node_piaozipos.children;
        for (let j = 0; j < children.length; j++) {
            const child = children[0];
            NodePoolMag.instance.recycleNodeToPool("piaozi", child);
        }

        this.twmove = cc.tween(this.node.children[0])
            .to(0.25, { scaleY: 0.9 })
            .to(0.25, { scaleY: 1 });

        cc.tween(this.node.children[0]).repeatForever(this.twmove).start();
    }

    /**
     * 建议方法名：addShield
     */
    async addShield() {
        this.nowHuDunNode = NodePoolMag.instance.getNodeFromPool("hudun");
        if (!this.nowHuDunNode) {
            const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_HuDun", cc.Prefab);
            NodePoolMag.instance.createNodePool("hudun", 1, prefab);
            this.nowHuDunNode = NodePoolMag.instance.getNodeFromPool("hudun");
        }

        this.auto_ui.node_hudunnode.addChild(this.nowHuDunNode);
        this.nowHuDunNode.getComponent(ViewShield).initializeHealth(100);
        this.iszhaohuan = false;
    }

    /**
     * 建议方法名：updateHealthBar
     */
    updateHealthBar() {
        if (this.xueliang <= 0) {
            this.handleMonsterDeath();
        }
    }

    /**
     * 建议方法名：handleMonsterDeath
     * @param e 死亡类型
     */
    handleMonsterDeath(e: number = 1) {
        if (!this.isDie) {
            BuffMgr.clearMonsterStack(this);
            BuffMgr.cleanMosterBomb(this.node.uuid);

            const poisonEffect = BuffMgr.getPoisonFog();
            if (this.iszhongdu && poisonEffect) {
                EventMgrInstance.emitEvent(EVENT_TYPE.Game_CreateDuWu, this, poisonEffect, this.dushangplayer);
            }

            if (this.ohterbullet && this.ohterbullet.attackfang) {
                BuffMgr.setBombDamage(this.ohterbullet.attackfang, this);
            }

            this.node.children.forEach(child => {
                child.active = false;
            });

            this.hunmoNode.active = true;
            this.hunmoNode.opacity = 255;

            cc.tween(this.hunmoNode)
                .to(0.5, { y: this.hunmoNode.y + 100 })
                .to(0.1, { opacity: 0 })
                .call(() => {
                    this.node.stopAllActions();
                    this.unscheduleAllCallbacks();
                    this.resetMonsterState();
                    NodePoolMag.instance.recycleNodeToPool("moster_" + this.mosterId, this.node);
                })
                .start();

            this.isDie = true;
            this.ismove = false;

            if (e === 1) {
                EventMgrInstance.emitEvent(EVENT_TYPE.Game_Moster_DIE, { moster: this.mosterId });
            }
        }
    }

    /**
     * 建议方法名：moveStep
     */
    moveStep() {
        if (this.ismove) {
            const targetNode = this.paths.children[this.moveindex];
            if (!targetNode) {
                this.handleMonsterDeath(2);
                EventMgrInstance.emitEvent(EVENT_TYPE.Game_Moster_Attack, { mosterId: this.mosterId });
                return;
            }

            const targetX = targetNode.x;
            const targetY = targetNode.y;

            if (this.moveindex === 0) {
                this.node.setPosition(targetX, targetY);
                this.moveindex += 1;
            } else {
                const direction = cc.Vec2.subtract(cc.v2(), cc.v2(targetX, targetY), this.node.getPosition());
                const angle = Math.atan2(direction.y, direction.x);
                const distance = cc.Vec2.distance(this.node.getPosition(), cc.v2(targetX, targetY));

                this.node.x += Math.cos(angle) * this.getCurrentSpeed();
                this.node.y += Math.sin(angle) * this.getCurrentSpeed();

                if (distance < 5) {
                    this.moveindex += 1;
                }
            }
        }

//         if (this.ismove) {
//             const targetNode = this.paths.children[this.moveindex];
//             if (!targetNode) {
//                 this.isDieMoster(2);
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Moster_Attack, { mosterId: this.mosterId });
//                 return;
//             }

//             const targetX = targetNode.x;
//             const targetY = targetNode.y;

//             if (this.moveindex === 0) {
//                 this.node.setPosition(targetX, targetY);
//                 this.moveindex += 1;
//             } else {
//                 const direction = cc.Vec2.subtract(cc.v2(), cc.v2(targattackuibetX, targetY), this.node.getPosition());
//                 const angle = Math.atan2(direction.y, direction.x);
//                 const distance = cc.Vec2.distance(this.node.getPosition(), cc.v2(targetX, targetY));

//                 this.node.x += Math.cos(angle) * this.nowspeed();
//                 this.node.y += Math.sin(angle) * this.nowspeed();

//                 if (distance < 5) {
//                     this.moveindex += 1;
//                 }
//             }
//         }
    }

    /**
     * 建议方法名：getNearbyMonsterNodes
     * @param e 距离
     * @returns 附近的怪物节点数组
     */
    getNearbyMonsterNodes(e: number): cc.Node[] {
        const siblings = this.node.parent.children;
        const nearbyNodes: cc.Node[] = [];

        for (let i = 0; i < siblings.length; i++) {
            const sibling = siblings[i];
            let distance = cc.Vec2.distance(sibling.getPosition(), this.node.getPosition());
            distance -= sibling.width / 2 + this.node.width / 2;

            if (distance <= e) {
                nearbyNodes.push(sibling);
            }
        }

        return nearbyNodes;
    }

    /**
     * 建议方法名：knockback
     * @param e 距离
     */
    knockback(e: number) {
        if (this.moveindex >= 2) {
            this.ismove = false;
            let targetIndex = this.moveindex - 1;
            if (targetIndex < 0) {
                targetIndex = 0;
            }

            const moveBack = (remainingDistance: number, index: number) => {
                const targetNode = this.paths.children[index];
                if (targetNode) {
                    const targetX = targetNode.x;
                    const targetY = targetNode.y;
                    const distance = cc.Vec2.distance(this.node.getPosition(), cc.v2(targetX, targetY));
                    let remaining = 0;

                    if (remainingDistance > distance) {
                        remaining = remainingDistance - distance;
                        remainingDistance = distance;
                    }

                    const direction = cc.Vec2.subtract(cc.v2(), cc.v2(targetX, targetY), this.node.getPosition());
                    const angle = Math.atan2(direction.y, direction.x);
                    const newX = this.node.x + Math.cos(angle) * remainingDistance;
                    const newY = this.node.y + Math.sin(angle) * remainingDistance;

                    cc.tween(this.node)
                        .to(0.1, { x: newX, y: newY })
                        .call(() => {
                            if (remaining > 0) {
                                moveBack(remaining, index - 1);
                            } else {
                                this.moveindex = index + 1;
                                this.scheduleOnce(() => {
                                    this.ismove = true;
                                }, 0.1);
                            }
                        })
                        .start();
                } else {
                    this.moveindex = index + 1;
                }
            };

            moveBack(e, targetIndex);
        }
    }

    /**
     * 建议方法名：receiveAttack
     * @param e 子弹
     * @param t 是否暴击
     */
    receiveAttack(e: any, t: boolean = false) {
        if (!this.isDie) {
            this.ohterbullet = e;
            let damage = e.getBulletAttack(this);
            const playerAttackBonus = BuffMgr.addPlayerAttack(this, e.attackfang);
            const bombBonus = BuffMgr.getMonsterBombBonus(this);
            let additionalDamage = 0;

            if (e.bulletId === 2) {
                additionalDamage = BuffMgr.getMonsterBombSailingCount(this);
            }

            let watermelonBonus = 0;
            if (this.isXiGuaBomb) {
                watermelonBonus = BuffMgr.getMonsterBombDamageIncrease();
            }

            damage += damage * (playerAttackBonus + bombBonus + additionalDamage + watermelonBonus);
            damage += BuffMgr.getFixedAttack(e.attackfang);

            this.playHitEffect();

            let damageType = 1;
            if (e.isbaoji) {
                damageType = 2;
            }
            if (e.bulletId === 2 || t) {
                damageType = 5;
            }

            this.reduceHealth(damage, damageType, e.attackfang);
        }
    }

    /**
     * 建议方法名：reduceHealth
     * @param e 伤害值
     * @param t 伤害类型
     * @param o 攻击方
     */
    reduceHealth(e: number, t: number, o: any) {
        if (this.nowHuDunNode) {
            const shieldComponent = this.nowHuDunNode.getComponent(ViewShield);
            shieldComponent.reduceHealth(e);

            if (shieldComponent.xuelinag < 0) {
                this.nowHuDunNode = null;
            }
        } else {
            e = BuffMgr.getTotalMonsterDamage(e);
            this.mosterXueTiao.decreaseBlood(e);
            this.xueliang -= e;
            this.updateHealthBar();
        }

        const hitPosition = this.auto_ui.node_piaozipos;
        if (o && o.playerId) {
            GameGlobalVariable.recordAttack(o.playerId, e);
        }

        EventMgrInstance.emitEvent(EVENT_TYPE.Game_ShangHai_FeiZi, e, hitPosition.convertToWorldSpaceAR(cc.v2()), null, t);
    }

    /**
     * 建议方法名：applyAdditionalAttack
     * @param e 伤害值
     * @param t 伤害类型
     * @param o 子弹
     */
    applyAdditionalAttack(e: number, t: number, o: any) {
        if (!this.isDie) {
            this.ohterbullet = o;
            this.playHitEffect();
            this.reduceHealth(e, t, o);
        }
    }

    /**
     * 建议方法名：playHitEffect
     */
    playHitEffect() {
        const sprite = this.node.children[0].getChildByName("item").getComponent(cc.Sprite);
        const tweenValue = { value: 0 };

        cc.tween(tweenValue)
            .to(0.1, { value: 1 }, {
                onUpdate: () => {
                    sprite.getMaterial(0).setProperty("u_rate", tweenValue.value);
                }
            })
            .call(() => {
                sprite.getMaterial(0).setProperty("u_rate", tweenValue.value);
            })
            .start();
    }

    /**
     * 建议方法名：getCurrentSpeed
     * @returns 当前速度
     */
    getCurrentSpeed(): number {
        let speed = 0;

        if (this.isdongjie) {
            speed = 0;
        } else {
            const minSpeed = 0.3 * this.mosterspeed;
            const speedReduction = BuffMgr.getCurrentSpeedRatio();
            speed = this.mosterspeed - this.mosterspeed * (this.bingdongjianshu + speedReduction);

            if (speed < minSpeed) {
                speed = minSpeed;
            }
        }

        return speed * GameGlobalVariable.jiasuState;
    }

    /**
     * 建议方法名：resetMonsterState
     */
    resetMonsterState() {
        this.isjianshu = false;
        this.isdongjie = false;
        this.iszhongdu = false;
        this.isliuxue = false;
        this.isransao = false;
        this.dushan = 0;
        this.bingdongjianshu = 0;
    }

    /**
     * 建议方法名：applySlowEffect
     * @param e 减速值
     * @param t 持续时间
     * @param o 攻击方
         */
    applySlowEffect(e: number, t: number, o: any) {
        if (!(this.isjianshu && !BuffMgr.isStacked(o))) {
            this.diejiacount += 1;
            if (this.diejiacount >= 3) {
                this.diejiacount = 3;
            }
            this.unschedule(this.resetFreezeValue);
            this.addFreezeEffect();
            this.isjianshu = true;
            this.bingdongjianshu = (e / 100) * this.diejiacount;
            this.scheduleOnce(this.resetFreezeValue, t);
            this.setFrozenImage(true, this.diejiacount);
            LogMgr.debug("冰冻减速效益", this.bingdongjianshu);
        }
    }

    /**
     * 建议方法名：addPoisonEffect
     */
    async addPoisonEffect() {
        this.zhongduNode = NodePoolMag.instance.getNodeFromPool("zhongdu");
        if (!this.zhongduNode) {
            const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_ZhongDu", cc.Prefab);
            NodePoolMag.instance.createNodePool("zhongdu", 1, prefab);
            this.zhongduNode = NodePoolMag.instance.getNodeFromPool("zhongdu");
        }

        this.zhongduNode.x = 0;
        this.zhongduNode.y = 0;
        GameGlobalVariable.effNode.addChild(this.zhongduNode);
    }

    /**
     * 建议方法名：removePoisonEffect
     */
    removePoisonEffect() {
        if (this.zhongduNode) {
            NodePoolMag.instance.recycleNodeToPool("zhongdu", this.zhongduNode);
            this.zhongduNode = null;
        }
    }

    /**
     * 建议方法名：addFreezeEffect
     */
    async addFreezeEffect() {
        // 这里可以添加冰冻效果的实现
    }

    /**
     * 建议方法名：updateEffects
     */
    updateEffects() {
        if (this.zhongduNode) {
            this.zhongduNode.setPosition(this.node.getPosition());
        }
        if (this.dongjieNode) {
            this.dongjieNode.setPosition(this.node.getPosition());
        }
    }

    /**
     * 建议方法名：removeFreezeEffect
     */
    removeFreezeEffect() {
        if (this.bingdongNode) {
            NodePoolMag.instance.recycleNodeToPool("bingshuang", this.bingdongNode);
            this.bingdongNode = null;
        }
    }

    /**
     * 建议方法名：addFrozenEffect
     */
    async addFrozenEffect() {
        if (this.isdongjie) {
            return;
        }

        AudioMgr.playSoundEffect("sound/冻结", false, BundleNames.Game);
        this.dongjieNode = NodePoolMag.instance.getNodeFromPool("dongjie");
        if (!this.dongjieNode) {
            const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_BingDong", cc.Prefab);
            NodePoolMag.instance.createNodePool("dongjie", 1, prefab);
            this.dongjieNode = NodePoolMag.instance.getNodeFromPool("dongjie");
        }

        this.dongjieNode.x = 0;
        this.dongjieNode.y = 0;
        GameGlobalVariable.effNode.addChild(this.dongjieNode);
    }

    /**
     * 建议方法名：removeFrozenEffect
     */
    removeFrozenEffect() {
        if (this.dongjieNode) {
            NodePoolMag.instance.recycleNodeToPool("dongjie", this.dongjieNode);
            this.dongjieNode = null;
        }
    }

    /**
     * 建议方法名：addBleedEffect
     */
    async addBleedEffect() {
        if (this.isliuxue) {
            return;
        }

        if (this.liuxueContentNode) {
            this.liuxueNode = NodePoolMag.instance.getNodeFromPool("liuxue");
            if (!this.liuxueNode) {
                const prefab = await this._loadRes(BundleNames.Game, "prefabs/effpre/UI_LiuXue", cc.Prefab);
                NodePoolMag.instance.createNodePool("liuxue", 1, prefab);
                this.liuxueNode = NodePoolMag.instance.getNodeFromPool("liuxue");
            }

            this.liuxueNode.x = 0;
            this.liuxueNode.y = 0;
            this.liuxueNode.width = this.liuxueContentNode.width;
            this.liuxueNode.height = this.liuxueContentNode.height;
            this.liuxueContentNode.addChild(this.liuxueNode);
        }
    }

    /**
     * 建议方法名：removeBleedEffect
     */
    removeBleedEffect() {
        if (this.liuxueNode) {
            NodePoolMag.instance.recycleNodeToPool("liuxue", this.liuxueNode);
            this.liuxueNode = null;
        }
    }

    /**
     * 建议方法名：setFrozenImage
     * @param e 是否显示
     * @param t 图片索引
     */
    async setFrozenImage(e: boolean, t: number) {
        if (this.isDie) {
            return;
        }

        if (e) {
            GameGlobalVariable.playHitSoundEffect();
            this.node.getChildByName("dongImg").active = true;
            const spriteFrame = await this._loadRes(BundleNames.Common, `res/player/${t}`, cc.SpriteFrame);
            this.node.getChildByName("dongImg").getComponent(cc.Sprite).spriteFrame = spriteFrame;
        } else {
            this.node.getChildByName("dongImg").active = false;
        }
    }

    /**
     * 建议方法名：applySpeedReduction
     * @param e Buff效果
     * @param t 攻击方
     */
    applySpeedReduction(e: any, t: any) {
        this.nowbuffatackplay = t;

        switch (e.buffefftype) {
            case 2:
                const isStackable = BuffMgr.isStacked(t);
                if (!(this.isjianshu && !isStackable)) {
                    this.diejiacount += 1;
                    if (this.diejiacount >= 3) {
                        this.diejiacount = 3;
                    }
                    this.unschedule(this.resetFreezeValue);
                    this.addFreezeEffect();
                    this.isjianshu = true;
                    this.jianshutime = e.bufftime;
                    this.bingdongjianshu = (e.value[0] / 100) * this.diejiacount;
                    this.scheduleOnce(this.resetFreezeValue, e.bufftime);
                    this.setFrozenImage(true, this.diejiacount);
                    LogMgr.debug("冰冻减速效益", this.bingdongjianshu);
                }
                break;
            case 5:
                Excel.shuiguoguaiwu(this.mosterId);
                if (Math.random() <= e.probability / 100) {
                    if (this.isdongjie) {
                        return;
                    }
                    this.addFrozenEffect();
                    this.isdongjie = true;
                    this.dongjietime = e.bufftime;
                    LogMgr.debug("冻结效益", this.isdongjie);
                }
                break;
            case 1:
                this.dushan = e.value[0] / 100;
                if (this.iszhongdu) {
                    return;
                }
                this.addPoisonEffect();
                this.dushangplayer = t;
                this.iszhongdu = true;
                this.zhongdutime = e.bufftime;
                break;
            case 22:
                if (this.isliuxue) {
                    return;
                }
                this.addBleedEffect();
                this.liuxueshang = e.value[0] + e.value[0] * BuffMgr.getBleedBonus(t);
                this.isliuxue = true;
                this.liuxuetime = e.bufftime;
                break;
            case 24:
                if (this.isransao) {
                    return;
                }
                this.ransaoshang = e.value[0];
                this.isransao = true;
                this.ransaotime = e.bufftime;
        }
    }

    /**
     * 建议方法名：resetFreezeValue
     */
    resetFreezeValue() {
        this.bingdongjianshu = 0;
        this.isjianshu = false;
        this.diejiacount = 0;
        this.removeFreezeEffect();
        this.setFrozenImage(false, 0);
    }

    /**
     * 建议方法名：resetFrozenState
     */
    resetFrozenState() {
        this.isdongjie = false;
        this.removeFrozenEffect();
    }

    /**
     * 建议方法名：applyPoisonDamage
     */
    applyPoisonDamage() {
        const poisonDamage = BuffMgr.getPoisonDamage();

        let totalDamage = BuffMgr.applyAttackBonus(this.dushangplayer, this.dushangplayer.sgattack, 1) * this.dushan;

        if (poisonDamage) {
            totalDamage += totalDamage * (poisonDamage.value[0] / 100);
        }

        this.reduceHealth(totalDamage, 3, this.nowbuffatackplay);


        //         if (poisonDamage) {
//             totalDamage += totalDamage * (poisonDamage.value[0] / 100);
//         }

//         this.jianxue(totalDamage, 3, this.nowbuffatackplay);
    }

    /**
     * 建议方法名：applyBleedDamage
     */
    applyBleedDamage() {
        this.reduceHealth(this.liuxueshang, 4, this.nowbuffatackplay);
    }

    /**
     * 建议方法名：applyBurnDamage
     */
    applyBurnDamage() {
        this.reduceHealth(this.ransaoshang, 5, this.nowbuffatackplay);
    }

    /**
     * 建议方法名：updateComponent
     * @param dt 时间增量
     */
    onUpdate(dt: number) {
        this.moveStep();
        this.updateEffects();

        if (this.isransao) {
            this.ransaotimeleiji += dt;
            if (this.ransaotimeleiji >= 1) {
                this.applyBurnDamage();
                this.ransaotime -= 1;
                if (this.ransaotime <= 0) {
                    this.isransao = false;
                }
                this.ransaotimeleiji = 0;
            }
        }

        if (this.iszhongdu) {
            this.dutimeleiji += dt;
            if (this.dutimeleiji >= 1) {
                this.applyPoisonDamage();
                this.zhongdutime -= 1;
                if (this.zhongdutime <= 0) {
                    this.removePoisonEffect();
                    this.iszhongdu = false;
                }
                this.dutimeleiji = 0;
            }
        }

        if (this.isliuxue) {
            this.liutimeleiji += dt;
            if (this.liutimeleiji >= 1) {
                this.applyBleedDamage();
                this.liuxuetime -= 1;
                if (this.liuxuetime <= 0) {
                    this.removeBleedEffect();
                    this.isliuxue = false;
                }
                this.liutimeleiji = 0;
            }
        }

        if (this.isdongjie) {
            this.dongjieleiji += dt;
            if (this.dongjieleiji >= 1) {
                this.dongjietime -= 1;
                if (this.dongjietime <= 0) {
                    this.resetFrozenState();
                }
                this.dongjieleiji = 0;
            }
        }

        if (this.iszhaohuan) {
            this.zhaohuantimeleiji += dt;
            if (this.zhaohuantimeleiji >= 1) {
                EventMgrInstance.emitEvent(EVENT_TYPE.Game_ZhaoHuan_Moster, this);
                this.zhaohuantimeleiji = 0;
            }
        }
    }
}
